<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class UserTranslateRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()) {
            case 'GET':
            case 'POST':
                return $this->getRules();
            default:
                return [
                    'type' => 'required'
                ];
        }
    }

    protected function getRules()
    {
        $rules = [ 'type' => 'required' ];//翻译类型:1：首翻 2：重译 3：改进
        if($this->get('type') == 1) //首翻
        {
            $rules['section_id'] = 'required|Numeric';
            $rules['time_long'] = 'Numeric|min:20';//表示2个字符
        }
        elseif($this->get('type') == 2) //重译
        {
            $rules['section_id'] = 'required';
        }
        elseif($this->get('type') == 3) //改进
        {
            $rules['record_id'] = 'required';
        }
        return $rules;
    }
}
